using System;
using System.Reflection;
using NBody;
using NBody.Analysis;
using OptionParser;
using Gsl;

[assembly: AssemblyTitle ("NBodyMorphology")]
[assembly: AssemblyVersion ("1.0.*")]
[assembly: AssemblyDescription ("Compute the morphology of an N-body system.\nWARNING:  YOU MAY HAVE TO USE \"LD_PRELOAD=/usr/lib/libgslcblas.so\" before command")]
[assembly: AssemblyCopyright ("2005 Joseph D. MacMillan")]

public class MorphologyOptions : InputOutputGetOptions
{
    [Option ("-e", "Desired tolerance")]
    public double Tolerance;
    
    [Option ("-c", "Adjust for centre of mass")]
    public bool CentreOfMass;
    
    [Option ("-m", "Don't use modified inertial tensor")]
    public bool NotModified;
    
    public MorphologyOptions()
    {
        Tolerance = 1e-5;
    }
}

public class NBodyMorphology
{
    static bool modified;
    
    public static void Main(string[] args)
    {
        MorphologyOptions opts = new MorphologyOptions();
        opts.ProcessArgs(args, ".morph");
        modified = !opts.NotModified;
                        
        NBodySystem sys = NBodySystem.Read(opts.InFile);
        
        if (opts.CentreOfMass)
            sys.AdjustForCentreOfMass(1e-3);
        
        double q, s;
        Shape.CalculateGlobal(ref sys, out q, out s, opts.Tolerance);
        
        Console.WriteLine("q = {0}", q);
        Console.WriteLine("s = {0}", s);
        
        sys.Write(opts.OutFile);        
    }
}
